<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="stylesheet" href="/static/css/font.css">
  <link rel="stylesheet" href="/static/css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="/static/js/xadmin.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-body ">
          <form class="layui-form layui-col-space5" id="myform" onsubmit="return false">
            <div class="layui-input-inline layui-show-xs-block">
              <input class="layui-input" placeholder="学校名" name="title"></div>
            <input type="hidden" name="pid" value="0">
            <div class="layui-input-inline layui-show-xs-block">
              <button class="layui-btn"  onclick="addCate()"><i class="layui-icon"></i>增加</button>
              <!--<button class="layui-btn"  onclick="location.href='/index/index/welcome'"><i class="layui-icon"></i>导入</button> -->
            </div>
          </form>
          <hr>
          <!--<a class="layui-btn layui-btn-sm"  onclick="F_Open_dialog()">导入分组</a>-->
          <!--<a class="layui-btn layui-btn-sm"  href="/uploads/模板.xlsx">下载分组模板</a>-->
        </div>

        <div class="layui-card-body ">
          <table class="layui-table layui-form">
            <thead>
            <tr>

              <th width="70">ID</th>
              <th>分类名称</th>
              <th width="80">是否允许上报</th>
              <th width="250">操作</th>
            </thead>
            <tbody class="x-cate">
            {volist name="cate" id="v"}
            <tr cate-id="{$v.id}" fid={$v.pid} >

              <td>{$v.id}</td>
              <td>
                <!--<i class="layui-icon x-show" status='true'>&#xe623;</i>-->
                <?php echo $v['title']?>
              </td>
              <td>
                <!--<button class="layui-btn layui-btn layui-btn-xs"  onclick="disCate({$v.id},{$v.status})" n>{if $v.status == 1}是{else/}否{/if}</button>-->
                <input type="checkbox" {if $v.status == 1}checked=""{/if} value="{$v.id}" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
              </td>
              <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑','editSchool/?id={$v.id}',600,400)" >
                  <i class="layui-icon">&#xe642;</i>编辑
                </button>
                <!--<button class="layui-btn layui-btn layui-btn-danger"  onclick="del({$v.id})" >-->
                <!--  <i class="layui-icon">&#xe642;</i>删除-->
                <!--</button>-->
                <!--<button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="xadmin.open('编辑','addCate/?pid={$v.id}',600,400)" >-->
                <!--  <i class="layui-icon">&#xe642;</i>添加子分类-->
                <!--</button>-->
              </td>
            </tr>
            {/volist}
            </tbody>
          </table>
        </div>
        <div class="layui-card-body ">
          <div class="page">
            <div>
                {$page|raw}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<input type="file" id="btn_file" onchange="upexcel()" style="display:none">
<script>
  function F_Open_dialog(){
    document.getElementById("btn_file").click();
  }
  function upexcel(){
    layer.confirm('确认提交?', function(index){
      var formData = new FormData();
        
      formData.append("file",$('#btn_file')[0].files[0]);
      $.ajax({
        url:'/index/wei/addschool',
        dataType:'json',
        type:'POST',
        async: false,
        data: formData,
        processData : false, // 使数据不做处理
        contentType : false, // 不要设置Content-Type请求头
        success: function(data){
        //   console.log(data);
          if (data.status == '1') {
            alert('上传成功！');
          }else{
            alert(data.msg);
          }

        },
        error:function(response){
          console.log(response);
        }
      });

      layer.close(index);
    });


  }
  layui.use(['form', 'layer'], function(){
    form = layui.form;
    form.on('switch(switchTest)', function(data){
            // console.log(data);
            if(this.checked){
                var status = 2;  
            }else{
                var status = 1;
            }
            $.ajax({
              url:"/index/wei/delschool",
              type:"post",
              data:{id:data.value,status:status},
              dataType:"json",
              success:function (res) {
                if (res.code){
                  layer.alert('操作成功', {
                            icon: 6
                          },
                          function () {
                            window.location.href="";
                          })
                }else{
                  layer.alert('网络开小差了', {
                    icon: 5
                  })
                }
              }
            })
          });

  });
    function del(){
            
    }
  function addCate() {

    layer.prompt({title: '输入学校名称，并确认', formType: 0}, function(pass, index){
      layer.msg(pass);
           $.ajax({
              url:"/index/wei/addschool",
              type:"post",
              data:{title:pass},
              dataType:"json",
              success:function (res) {
                if (res.code){
                  layer.alert(res.msg, {
                    icon: 6
                  }, function(){
                    location.href=""
                  })
                }else{
                  layer.alert(res.msg, {
                    icon: 5
                  })
                }
              }
            })
    });
  }

  function disCate(id,status) {
    $.ajax({
      url:"/index/wei/delschool",
      type:"post",
      data:{id:id,status:status},
      dataType:"json",
      success:function (res) {
        if (res.code){
          layer.alert('操作成功', {
                    icon: 6
                  },
                  function () {
                    window.location.href="";
                  })
        }else{
          layer.alert('网络开小差了', {
            icon: 5
          })
        }
      }
    })

  }





</script>
</body>
</html>
